﻿using System.Collections.Generic;
using UnityEngine;

namespace Gj
{
    public class OverlayItem : MonoBehaviour
    {
        public string key;
        public bool show;
        public List<OverlayText> list = new();
        public Element element;
        protected Vector3 point;

        public virtual void Refresh(Camera camera)
        {
            point = camera.WorldToScreenPoint(element.GetPosition());
            if (point.z < 0) point = point * -1;
            point.z = 0;
            transform.position = point;
        }

        public void Show()
        {
            show = true;
            gameObject.SetActive(true);
        }

        public void Hide()
        {
            show = false;
            gameObject.SetActive(false);
        }

        public virtual void Select()
        {
        }

        public virtual void Cancel()
        {
        }

        public virtual string GetName()
        {
            return element.GetName();
        }

        public void Click()
        {
            OverlayService.single.OnClick(key, this);
        }

        public void Refresh()
        {
            OverlayService.single.OnRefresh(this);
        }
        
        protected bool CheckIn()
        {
            return point.x > SystemInput.screenMin.x && point.x < SystemInput.screenMax.x && point.y > SystemInput.screenMin.y && point.y < SystemInput.screenMax.y;
            if (point.z < 0) point = point * -1;
            point.z = 0;
            transform.position = point;
        }

    }
}